<@html>
<link rel="stylesheet" href="${path}/js/dojo/dojox/grid/resources/${theme}Grid.css">
<script type="text/javascript" src="${path}/js/dojo/dojo/inputForm.js"></script>
<script type="text/javascript" src="${path}/js/dojo/dojo/naviGrid.js"></script>
<script type="text/javascript">
	//dojo.require("dijit.dijit");
	//dojo.require("dijit.form.Form");
	//dojo.require("dijit.form.TextBox");
	//dojo.require("dojox.data.QueryReadStore");
	//dojo.require("widget.navgrid.NavGrid");
</script>
<@queryForm>
<TABLE class=queryTable cellSpacing=0 width="100%" align=center border=0>
	<tr>
		<td width="9%" class="right">
			角色编号<@splitor/>
		</td>
		<td width="18%">
			<input dojoType="dijit.form.TextBox" name="role.roleCode" type="text" id="roleCode"
			       size="15"/>
		</td>
		<td width="9%" class="right">
			角色名称<@splitor/>
		</td>
		<td width="18%">
			<input dojoType="dijit.form.TextBox" name="role.roleName" type="text" id="roleName"
			       size="15"/>
		</td>
	</tr>
</TABLE>
</@queryForm> <@toolbar/>
<table jsId="grid" id="grid" dojoType="widget.navgrid.NavGrid"
       selectionMode="single" store="store" rowsPerPage="10"
       structure="layout" autoHeight="10">
</table>
</@html>
<script type="text/javascript">
	var store = new dojox.data.QueryReadStore({
				url : '${path}/system/role.list.do',
				requestMethod : "post"
			});
	var layout = [
		{
		},
		{
			cells : [
				[
					//new dojox.grid.cells.RowIndex({ width:"4%",name:"序号" }),
					{
						name : '角色代码',
						headerClasses:"gridHeader",
						field : 'roleCode',
						width : "25%"
					},
					{
						name : '角色名称',
						headerClasses:"gridHeader",
						field : 'roleName',
						width : "40%"
					}
				]
			]
		}
	];
	dojo.ready(function() {
		//事件注册
		//新增
		dojo.connect(dijit.byId("btnAdd"), "onClick", function() {
			parent.openDialog({
						url : 'role.load.do',
						title : '新增角色',
						width : 800,
						height : 600
					});
		})
		//编辑
		dojo.connect(dijit.byId("btnEdit"), "onClick", function() {
			var id = store.getValue(grid.selection.getSelected()[0], "id");
			parent.openDialog({
						url : 'role.load.do?role.id=' + id,
						title : '修改角色信息',
						width : 800,
						height : 600
					});
		})
		//删除
		dojo.connect(dijit.byId("btnDelete"), "onClick", function() {
			if (!grid.selection.getSelected() || grid.selection.getSelected().length == 0) {
				parent.Error("您未选择数据！");
				return;
			}
			var id = store.getValue(grid.selection.getSelected()[0], "id");
			parent.Confirm({
						msg : "确认删除数据吗？",
						okCall : function() {
							dojo.xhrGet({
										url:"${path}/system/role.delete.do?role.id=" + id,
										handleAs:"json",
										load:function(json) {
											handleJsonMessage({
														message:json,
														callback:function() {
															grid.reload();
														}
													})
										}
									})
						}
					})
		})
		//查询
		dojo.connect(dijit.byId("btnQuery"), "onClick", function() {
			grid.setQuery(dojo.formToObject(dojo.byId('queryForm')));
		})
		//注册响应函数
		parent.subscribe("${pageId!}", "role/save", window, function() {
			grid.reload();
		})
	})
</script>
